package taller2.model.graph;

import java.io.Serializable;

import taller2.interfaces.Connection;
import taller2.interfaces.Node;
import taller2.utils.Constants;

public class ConnectionImpl implements Serializable, Connection{
    private static final long serialVersionUID = 1L;
    private boolean selected;
    private int weight;
    private int capacity;
    private int flux;
    private Node thisNode;
    private Node other;

       public Node getThisNode() {
        return thisNode;
    }

    // constructor
    public ConnectionImpl(int connWeight, Node thisNode, Node otherNode){
        this.weight = connWeight;
        this.thisNode = thisNode;
        this.other = otherNode;
        this.capacity = Constants.FluxConnKilled;
        this.flux = Constants.FluxConnKilled;
        this.selected = false;
    }

    //copy constructor
    public ConnectionImpl(ConnectionImpl connection) {
        this.weight = connection.getWeight();
        this.thisNode = new NodeImpl(connection.getThisNode());
        this.other = new NodeImpl(connection.getOtherNode());
        this.capacity = connection.getCapacity();
        this.flux = connection.getFlux();
        this.selected = false;
    }

    // returns the weigh of the connection
    public int getWeight(){
        return weight;
    }

	// changes the weigh of the connection
	public void setWeight(int weight){
		this.weight = weight;
	}

    
    // returns the other node
    public Node getOtherNode(){
        return other;
    }

    // returns true if the connection is selected
    public boolean isSelected(){
        return selected;
    }

    // marks the selection to be shown in a different color
    public void select(){
        this.selected = true;
    }

    // unmarks the selection to be shown normally
    public void unselect(){
        this.selected = false;
    }

    public String getID() {
    	return thisNode.getID()+ ',' + other.getID();
    }

	public int getCapacity() {
		return capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}

	public int getFlux() {
		return flux;
	}

	public void setFlux(int flux) {
		this.flux = flux;
	}
}
